<?php
// Index.php
// Main portal

require_once("functions.php");

// Check to see if logged in
session_start();

$my_city = Null;

if(isset($_SESSION['user'])){
  // Get user info
  $userinfo = query_select("
    SELECT username, default_city
    FROM user
    WHERE id = " . $_SESSION['user']
  );

  $username = $userinfo[0]['username'];
  $my_city = $userinfo[0]['default_city'];
}
$cities = query_select("
 SELECT *
 FROM city
 ORDER BY name ASC
");

?>


<?php require_once("header.php"); ?>


<img src = "./layout/indextitle.png" />
<p class="text2">Select a city from below to begin searching information. <br/> Once you have selected a city you can make it your default city.</p>
<div id = "citiesbox">
  <div id = "citiescurved"></div>
  <div id = "cities">
    <table>
    <?php
      $i = 0;
      $size = count($cities) / 7;
      foreach($cities as $city){
        if ($i == 0 ) {
          echo '<table class = "floater">';
        }
      
        echo '<tr><td>';
        echo '<a class = "city" href="city.php?id=' . $city['id'] . '">' . ucwords($city['name']) . '</a>';
        echo '</td></tr>';
        $i++;
      if ($i == 70) {
        echo '</table>';
        $i = 0;
      }	
      
    }
      
    ?>
    </table>
    <div class="clear"> <!-- keeps floats within parent container --></div> 
  </div>
</div>

<?php require_once("footer.php"); ?>
